<include file="Public/header" />
<script type="text/javascript">
function ajax_settle(){
	$.getJSON(AdminUrl+'c=Settle&a=ajax_settle', function(result){
        if(result.done){
            alert('结算操作已完成');
            window.location.href=AdminUrl+'c=Settle&a=settle_manage';
        }else{
        	alert(result.msg);
        }
    });
}
</script>
<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3>结算管理</h3>
      <ul class="tab-base">
        <li><a href="javascript:void(0);" class="current"><span>管理</span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form method="get" name="formSearch">
    <table class="tb-type1 noborder search">
      <tbody>
        <tr>
          <th>商铺名称</th>
          <td><input type="text" value="{$search['store_name']}" name="store_name" class="txt" ></td>
          <th>结算状态</th>
          <td>
			  <select name='state'>
			    <option value="">全部结算单</option>
				<option value="1" <if condition="$search['state'] eq 1">selected</if>>已出账</option>
				<option value="2" <if condition="$search['state'] eq 2">selected</if>>已审核</option>
				<option value="3" <if condition="$search['state'] eq 3">selected</if>>已确认</option>
				<option value="4" <if condition="$search['state'] eq 4">selected</if>>已支付</option>
				<option value="5" <if condition="$search['state'] eq 5">selected</if>>已完成</option>
			  </select>
          </td>
          <td><a href="javascript:document.formSearch.submit();" class="btn-search tooltip" title="查询">&nbsp;</a>
          </td><td></td><td></td>
          <td><a href="javascript:ajax_settle();" class="btn-add tooltip">开始结算</a></td>
        </tr>
      </tbody>
    </table>
  </form>
  <!-- 操作说明 -->
  <table class="table tb-type2" id="prompt">
    <tbody>
      <tr class="space odd">
        <th colspan="12" class="nobg">
        	<div class="title">
	            <h5>操作提示</h5>
	            <span class="arrow"></span>
            </div>
        </th>
      </tr>
      <tr>
        <td>
		  <ul>
            <li>点击“开始结算”按钮将对截至昨日的未结算订单进行批量结算汇总</li>
            <li>已消费的团购订单才会被结算</li>
          </ul>
		</td>
      </tr>
    </tbody>
  </table>
  <form id="list_form" method='post'>
    <table class="table tb-type2">
      <thead>
        <tr class="space">
          <th colspan="15" class="nobg">列表</th>
        </tr>
        <tr class="thead">
          <th class="w200">结算单号</th>
          <th class="w200">商铺名称</th>
		  <th class="w200">起始日期</th>
		  <th class="w200">结束日期</th>
          <th class="w200">订单金额</th>
          <th class="w200">结算金额</th>
		  <th class="w200">结算日期</th>
		  <th class="w60">结算状态</th>
		  <th class="w200 align-center">操作</th>
        </tr>
      </thead>
      <tbody>
        <notempty name="list">
        <volist name="list" id="val">
        <tr class="hover edit">
          <td>{$val['settle_sn']}</td>
		  <td><a href="#" target="_blank">{$val['store_name']}</a></td>
		  <td>{$val['date_start']|date='Y-m-d H:i:s',###}</td>
		  <td>{$val['date_end']|date='Y-m-d H:i:s',###}</td>
		  <td>{$val['amount']}元</td>
		  <td>{$val['final_pay']}元</td>
		  <td>{$val['settle_time']|date='Y-m-d H:i:s',###}</td>
		  <td>
            <switch name="val.state">    
                <case value="1">已出账</case>    
                <case value="2">已审核</case>    
                <case value="3">已确认</case> 
                <case value="4">已支付</case> 
                <case value="5">已完成</case>  
            </switch>         
		  </td>
		  <td class='align-center'>
            <switch name="val.state">    
                <case value="1">
                <a hidden='javascript:if(confirm("确定进行此操作吗？"))window.location.href="{:U('Settle/settle_state_change',array('settle_id'=>$val['settle_id'],'new_state'=>2))}"'>	审核</a>
                </case>    
                <case value="2">已审核，等待商家确认</case>    
                <case value="3">
                <a hidden='javascript:if(confirm("确定进行此操作吗？"))window.location.href="{:U('Settle/settle_state_change',array('settle_id'=>$val['settle_id'],'new_state'=>4))}"'>	支付</a>
                </case> 
                <case value="4">已支付，等待商家确认</case> 
                <case value="5">--</case>  
            </switch>           
			&nbsp;&nbsp;<a href="{:U('Settle/settle_detail',array('settle_id'=>$val['settle_id']))}">明细</a>
		  </td>
        </tr>
        </volist>
        <else />
        <tr class="no_data">
          <td colspan="10">暂无记录</td>
        </tr>
        </notempty>
      </tbody>
      <notempty name="list">
      <tfoot>
        <tr class="tfoot">
          <td id="batchAction" colspan="15">
            <div class="pagination">{$show_page}</div>
          </td>
        </tr>
      </tfoot>
      </notempty>
    </table>
  </form>
</div>
<include file="Public/footer" />